//index.js
//获取应用实例
var app = getApp()
var fileData = require('../../utils/data.js')
var req = require('../../utils/reqUtils.js');

Page({
  // 页面初始数据
  data: {
    colors: fileData.getColor(0),
    tab: ['地址管理', '驾照管理', '订单管理'],
    tabIndex: 0,
    active: 0,
    loginImg: '../../image/login/login.png',
    user: null,
  },
  // 数据加载
  onLoad: function () {
    var index = this.data.curIndex
    wx.setNavigationBarColor({
      frontColor: '#ffffff', // 必写项【该字体颜色仅支持 #ffffff 和 #000000 】
      backgroundColor: this.data.colors.topColor, // 传递的颜色值【仅支持有效值为十六进制颜色】
    })

    req.get('/BookUserServlet', {
    }, 1)
    .then(res => {
      this.setData({
        user: res.data
      })
      req.get('/DriverLicenseServlet', {
        'id': this.data.user.userID
      }, 1)
      .then(res => {
        this.setData({
          licence: res.data,
          isHaveLicence: false
        })
        if (this.data.licence == null) {
          console.log("sss")
          this.setData({
            isHaveLicence: true
          })
        }
      })
    req.get('/OrderServlet', {
        'id': this.data.user.userID
      }, 1)
      .then(res => {
        this.setData({
          orders: res.data
        })
      })
    })
  },
  onChange(event) {
    this.setData({
      tabIndex: event.detail.name
    })
  },

  toLogin: function (e) {
    wx.navigateTo({
      url: '../login/login'
    })
  },

  // 地址编辑
  editAddr: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '../edit_addr/edit_addr?addrid=' + e.currentTarget.dataset.addrid
    })
  }

})